package com.example.designModel.strategy;

import org.springframework.beans.factory.BeanFactory;
import org.springframework.context.ApplicationContext;
import org.springframework.context.expression.MethodBasedEvaluationContext;
import org.springframework.core.DefaultParameterNameDiscoverer;
import org.springframework.core.ParameterNameDiscoverer;
import org.springframework.expression.EvaluationContext;
import org.springframework.expression.ExpressionParser;
import org.springframework.expression.spel.standard.SpelExpressionParser;
import org.springframework.expression.spel.support.StandardEvaluationContext;

import java.lang.reflect.Method;
import java.util.*;

public class MainMethod {
    private static final ParameterNameDiscoverer NAME_DISCOVERER = new DefaultParameterNameDiscoverer();

    public static void main(String[] args) {

//        CashContext context = new CashContext("打8折");
//        double totalPrice = 0;
//        totalPrice = context.GetResult(1000);
//        System.out.println(totalPrice);
//        CashReturn cashNormal = new CashReturn("300","200");
//        try {
//            Method method = cashNormal.getClass().getMethod("test", CashReturn.class);
//            Object[] arguments = new Object[]{cashNormal};
            ExpressionParser parser = new SpelExpressionParser();
//            EvaluationContext context = new MethodBasedEvaluationContext(null, method, arguments, NAME_DISCOVERER);
//            Object value = parser.parseExpression("#a.moneyCondition").getValue(context);
//            System.out.println(value.toString());
//
//        } catch (NoSuchMethodException e) {
//            e.printStackTrace();
//        }
        //1.测试集合或数组
        //2.测试字典
        Map<String, Integer> map = new HashMap<String, Integer>();
        map.put("a", 1);
        map.put("b", 2);
        EvaluationContext context2 = new StandardEvaluationContext();
        context2.setVariable("map", map);
        List<String> result2 = parser.parseExpression("#map.![key+1]").getValue(context2, List.class);
        result2.forEach(System.out::println);
    }
}
